package com.reform.controller.phase;


import com.reform.pojo.project.PhaseTime;
import com.reform.res.Result;
import com.reform.service.IPhaseTimeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.sql.SQLException;

/**
 * <p>
 * 阶段时间表 前端控制器
 * </p>
 *
 * @author mortale
 * @since 2021-07-15
 */
@Api(tags = "PhaseTimeController")
@RestController
@RequestMapping("/phase-time")
public class PhaseTimeController {

    @Autowired
    IPhaseTimeService phaseTimeService;

    @ApiOperation(value = "获取所有阶段检查信息")
    @GetMapping("/getAllPhase")
    public Result getAllPhase() throws SQLException {
        return phaseTimeService.getAllPhase();
    }

    @ApiOperation(value = "创建阶段检查")
    @PostMapping("/creatPhase")
    public Result creatPhase(PhaseTime phaseTime) throws SQLException {
        return phaseTimeService.creatBatchPhase(phaseTime);
    }

    @ApiOperation(value = "编辑阶段检查")
    @PostMapping("/updatePhase")
    public Result updatePhase(PhaseTime phaseTime) throws SQLException {
        return phaseTimeService.updatePhase(phaseTime);
    }

    @ApiOperation(value = "通过id获取阶段检查信息")
    @PostMapping("/getPhaseById")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phaseId", value = "阶段检查编号", paramType = "query", dataTypeClass = String.class, required = true),
    })
    public Result getPhaseById(String phaseId) throws SQLException {
        return phaseTimeService.getPhaseById(phaseId);
    }

    @ApiOperation(value = "删除阶段检查信息")
    @PostMapping("/deletePhaseById")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phaseId", value = "阶段检查编号", paramType = "query", dataTypeClass = String.class, required = true),
    })
    public Result deletePhaseById(String phaseId) throws SQLException {
        return phaseTimeService.deletePhaseById(phaseId);
    }

    @ApiOperation(value = "获取待办事项")
    @PostMapping("/getNeedDealtPhase")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "类型(1 =>教师  2 => 专家   3=>校管理员  4=>院管理员)", paramType = "query", dataTypeClass = Integer.class, required = true),
    })
    public Result getNeedDealtPhase(HttpServletRequest request, Integer type) throws SQLException {
        return phaseTimeService.getNeedDealtPhase(request, type);
    }

    @ApiOperation(value = "更改批次状态")
    @PostMapping("/updateBatchStatus")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "status", value = "批次状态（-1 申报 0学院审核 1学校初审 2专家审核 3学校二审 4）", paramType = "query", dataTypeClass = Integer.class, required = true),
            @ApiImplicitParam(name = "batchId", value = "批次编号", paramType = "query", dataTypeClass = String.class, required = true),
    })
    public Result updateBatchStatus(String batchId, Integer status) throws SQLException {
        return phaseTimeService.updateBatchStatusById(batchId, status);
    }

    @ApiOperation(value = "更改打分表")
    @PostMapping("/updateScore")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "scorePath", value = "打分表模板地址", paramType = "query", dataTypeClass = String.class, required = true),
            @ApiImplicitParam(name = "scorePathName", value = "打分表模板文件名", paramType = "query", dataTypeClass = String.class, required = true),
            @ApiImplicitParam(name = "batchId", value = "批次编号", paramType = "query", dataTypeClass = String.class, required = true),
    })
    public Result updateScore(String batchId, String scorePath,String scorePathName) throws SQLException {
        return phaseTimeService.updateScore(batchId, scorePath,scorePathName);
    }
}
